//
//  CZNewFeatureCell.swift
//  CZWeibo
//
//  Created by 周振兰 on 16/5/14.
//  Copyright © 2016年 周振兰. All rights reserved.
//

import UIKit

class CZNewFeatureCell: UICollectionViewCell
{
    //根据cell显示的哪一页设置对应的图片
    var index :Int = 0
        {
            didSet
                {
                    CZPrint(items: "第\(index)页要显示")
                    bkgImageView.image = UIImage(named: "new_feature_\(index+1)")
                    //隐藏开始按钮
                    startButton.hidden = true
            }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        prepareUI()
    }
    
    
 private func prepareUI ()
    {
        //添加控件
        
        contentView.addSubview(bkgImageView)
        contentView.addSubview(startButton)
        
        //添加约束
        bkgImageView.snp_makeConstraints { (make) -> Void in
            make.edges.equalTo(self.contentView)
           
        }
        startButton.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.contentView)
            make.bottom.equalTo(self.contentView).offset(-160)
        }
    }
    //开始动画
    func starAnimation()
    {
        //动画之前，将按钮显示出来
        startButton.hidden = false
        // 在动画前设置transform.scale为0.看不到
        startButton.transform = CGAffineTransformMakeScale(0, 0)
        UIView.animateKeyframesWithDuration(0.5, delay: 2, options: UIViewKeyframeAnimationOptions(rawValue: 0), animations: { () -> Void in
            
            self.startButton.transform = CGAffineTransformMakeScale(1, 1)
           //清空 transform到默认的状态 scale = 1
            }, completion: nil)
    }
    
    //MARK:- 懒加载
//背景imageView
    lazy var bkgImageView: UIImageView = UIImageView(image: UIImage(named: "new_feature_1"))
    
private  lazy  var startButton :UIButton =
        {
        //设置文字
            let button = UIButton()
            button.setTitle("开始体验", forState: UIControlState.Normal)
            button.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
            button.setBackgroundImage(UIImage(named: "new_feature_finish_button"), forState: UIControlState.Normal)
            button.setBackgroundImage(UIImage(named: "new_feature_finish_button_highlighted"), forState: UIControlState.Highlighted)
            button.hidden = true
            return button
    }()
}
